<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="胡爱静">
    <title>首页</title>
    <style>
        body {
            margin: 0;
        }

        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        * {
            box-sizing: border-box;
        }

        .num1 {
            width: 100%;
            height: 30px;
            line-height: 30px;
            border-bottom: 1px solid lightgray;
        }

        .first {
            width: 40%;
            display: flex;
            justify-content: space-between;
            text-align: center;
            float: right;
        }

        .ul1,
        .ul2 {
            display: flex;
            justify-content: space-around;
        }

        .ul1 li,
        .ul2 li {
            margin: 0 10px;
        }

        .ul1 a {
            font-weight: bold;
        }

        a {
            font-size: 14px;
            color: black;
        }

        .baidu {
            width: 48%;
            margin: 0 auto;
            display: flex;
            justify-content: space-around;
            margin-top: 20px;
            line-height: 65px;
        }

        .one img {
            width: 130px;
            height: 50px;
            cursor: pointer;
        }

        #input1 {
            width: 600px;
            height: 40px;
        }

        #input2 {
            width: 100px;
            height: 40px;
            cursor: pointer;
            background-color: #3388ff;
            border: 1px solid #3388ff;
            font-size: 15px;
            color: white;
            text-align: center;
            position: absolute;
            margin-top: 14px;
            margin-left: -100px;
        }

        .three a {
            margin: 0 5px;
        }

        form {
            width: 33%;
            margin: 0 auto;
            margin-bottom: 10px;
            font-size: 14px;
            color: #666666;
        }

        .long {
            width: 100%;
            height: 40px;
            line-height: 40px;
            background-color: #01204F;
            color: white;
            font-size: 14px;
        }

        .long-nav {
            width: 50%;
            position: relative;
            margin: 0 auto;
        }

        .long-nav ul {
            display: flex;
        }

        .long-nav li {
            margin: 0 6px;
            padding: 0 6px;
            cursor: pointer;
            z-index: 5;
            position: relative;
        }


.moren{
     width: 40px; 
    margin-right: 2px;
     background-color: #CC0000;
}
        .bg{
            width: 40px;
            height: 40px;
            position: absolute;
            top: 0;
            left:0;
            background-color: #CC0000;
            transition: all 0.3s linear;
        }
         main {
             width: 50%;
            margin: 0 auto;
            height: 2000px;
            background-color: #38f;
        }
         .back-to-top{
            width: 80px;
            height: 30px;
            background-color: red;
            text-align: center;
            line-height: 30px;
            position: fixed;
            right: 50px;
            bottom: -30px;
            cursor: pointer;
            transition: all 0.5s linear;
        }
    </style>
</head>

<body>
    <nav class="num1">
        <div class="first">
            <ul class="ul1">
                <li><a href="#">网页</a></li>
                <li><a href="#">新闻</a></li>
                <li><a href="#">贴吧</a></li>
                <li><a href="#">知道</a></li>
                <li><a href="#">音乐</a></li>
                <li><a href="#">图片</a></li>
                <li><a href="#">视频</a></li>
                <li><a href="#">地图</a></li>
                <li><a href="#">文库</a></li>
            </ul>
            <span>&#x3000;|&#x3000;</span>
            <ul class="ul2">
                <li><a href="#">百度首页</a></li>
                <li><a href="#">登录</a></li>
                <li><a href="#">注册</a></li>
                <li><a href="#">百度新闻客户端</a></li>
            </ul>
        </div>
    </nav>
    <nav class="baidu">
        <div class="one">
            <img src="baidu.png" alt="">
        </div>
        <div class="two">
            <input type="text" id="input1" checked><button type="button" id="input2">百度一下</button>
        </div>
        <div class="three">
            <span><a href="#">帮助</a></span>
            <span><a href="#">高级搜索</a></span>
            <span><a href="#">设置</a></span>
        </div>
    </nav>
    <form>
        <input type="radio" id="quanwen" value="" name="dan">
        <label for="quanwen">新闻全文</label>
        <input type="radio" id="title" value="" name="dan">
        <label for="title">新闻标题</label>
    </form>
    <nav class="long">
        <div class="long-nav">
            <ul>
                <li class="moren">首页</li>
                <li>百家号</li>
                <li>国内</li>
                <li>国际</li>
                <li>军事</li>
                <li>社会</li>
                <li>财经</li>
                <li>娱乐</li>
                <li>体育</li>
                <li>互联网</li>
                <li>科技</li>
                <li>游戏</li>
                <li>时尚</li>
                <li>女人</li>
                <li>汽车</li>
                <li>个性推荐</li>
                <li>
                    <span>更多</span><span>^</span>
                </li>
                <div class="bg"></div>
            </ul>
        </div>
    </nav>
    <main>
        
    </main>
    <div class="back-to-top">返回顶部</div>
               
</body>

</html>
<script>
    var nav = document.querySelector('.long');
    var body = document.querySelector('body');
    var lis = document.querySelectorAll('.long-nav ul li');
    var bg = document.querySelector('.bg');
    // var toTop = document.querySelector('.to-top');
    // console.log(long.offsetTop);
    window.onscroll = function () {
        var scrollTop = document.scrollingElement.scrollTop;
        if (scrollTop >= 160) {
            nav.style.position = 'fixed';
            nav.style.top = '0';
            nav.style.backgroundColor = '#01204F';
        } else {
            nav.style.position = 'static';
            nav.style.top = '0';
        }
        if(scrollTop >=300){
            backToTop.style.bottom = '30px';
        }else{
             backToTop.style.bottom = '-30px';
        }
    }
        for(var i = 0;i<lis.length;i++){
           lis[i].onmouseover = function () {
               bg.style.left = this.offsetLeft +'px';
               bg.style.width = this.offsetWidth + 'px';
           }
           lis[i].onmouseout = function(){
                bg.style.left = 0;
               bg.style.width = '60px';
           }
    }      
    
    //  点击返回顶部
    var backToTop = document.querySelector('.back-to-top');
    backToTop.onclick = function(){
        document.documentElement.scrollTop = document.body.scrollTop = '0';
    }

</script>